package com.android.delivery.activity

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import com.android.delivery.R
import com.android.delivery.activity.fragment.*
import com.android.delivery.adapter.BaseFragmentStateAdapter
import com.android.delivery.base.BaseActivity
import com.android.delivery.constant.Constants
import com.android.delivery.entity.Logistics
import kotlinx.android.synthetic.main.common_viewpager.*

/**
 * @author: mqwang
 * @create: 3/21/21 8:49 AM
 * @Description: 打印机-中心
 */
class PrintlnActivity : BaseActivity() {

    companion object{
        val REQUEST_CODE = 1
        val TAB_PRINT = 0
        val TAB_PRINT_CLOUD = 1;
    }
    private val mTitles: MutableList<String> = ArrayList()
    private val tabFragmentList: MutableList<Fragment> = ArrayList()

    override fun getLayoutId(): Int {
        return R.layout.common_viewpager
    }

    override fun init(savedInstanceState: Bundle?, container: View?) {
        setMainTitle("打印机")

        var logistics = intent.getParcelableExtra<Logistics>(Constants.ITEM)

        mTitles.add("蓝牙设备")
        mTitles.add("云打印")

        if (logistics == null){
            tabFragmentList.add(PrintlnBlueListFragment.newInstance())
        }else{
            tabFragmentList.add(PrintlnBlueListFragment.newInstance(logistics))
        }
        tabFragmentList.add(PrintlnCloudListFragment.newInstance())

        view_pager.setAdapter(BaseFragmentStateAdapter(supportFragmentManager, tabFragmentList, mTitles))
        tab_layout.setupWithViewPager(view_pager) //此方法就是让tablayout和ViewPager联动

        val type = intent.getIntExtra(Constants.TYPE, 0)
        view_pager.setCurrentItem(type, false)
    }
}